package thread;

public class SynoDemo1 {
    public static void main(String[] args) {
        Shop shop = new  Shop();
        Shop shop2 = new  Shop();

        /*Thread t1 = new Thread("李老师"){
            @Override
            public void run() {
                shop.buy();
            }
        };*/

        Thread t1 = new Thread(shop::buy);

        Thread t2 = new Thread("范老师"){
            @Override
            public void run() {
                shop2.buy();
            }
        };
        t1.start();
        t2.start();
    }

}

class Shop{
    public  void buy(){
        try {
            System.out.println(Thread.currentThread().getName()+"正在挑衣服");
            Thread.sleep(1000);

//            synchronized (new Object()){//永远锁不住,因为你里面量永远不同
            synchronized (this){
//            synchronized (123){
                System.out.println(Thread.currentThread().getName()+"正在试衣服");
                Thread.sleep(1000);
                System.out.println(Thread.currentThread().getName()+"试衣服结束");
            }

            System.out.println(Thread.currentThread().getName()+"结账");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}